<template>
	<view class="ag_container">
		<view class="agree_jn">
			<p class="per_title">
				<span><i class="iconfont">&#xe61b;</i>企业抄送方</span>
				<button size="mini" class="primay_btn" @click="confirm">确 定</button>
			</p>
			<uni-forms ref="ruleForm" :modelValue="ruleForm" :rules="rules" label-position="right"  class="personal_form">
			    <uni-forms-item  name="sendCompany" >
				<uni-easyinput v-model="ruleForm.sendCompany" type="text" placeholder="工商营业执照上的企业名称" suffixIcon="forward" prefixIcon="wallet" @iconClick="iconCompany" />
				</uni-forms-item>
			<uni-forms-item  name="sendName" >
			<uni-easyinput v-model="ruleForm.sendName" type="text" placeholder="经办人真实姓名" prefixIcon="person" suffixIcon="forward" @iconClick="iconClick" />
			</uni-forms-item>
			<uni-forms-item name="sendMobile" >
			<uni-easyinput v-model="ruleForm.sendMobile" type="text" placeholder="经办人实名手机号" prefixIcon="phone" />
			</uni-forms-item>
			</uni-forms>
		</view>
		<!-- 提示 -->
		<p class="remark">请填写抄送人真实姓名和实名手机号码。抄送人可查阅、下载合同文件，最多可抄送给10位伙伴。</p>
	</view>
	</view>
</template>

<script>
	import {addContractCopy} from "@/api/ec/work/contract/contract";
	export default {
		data() {
			return {
				ruleForm:{
					id: 0,
					sendCompany: "",
					sendMobile: "",
					sendName: "",
					companyContent: "",
					senderType: 0,         
				},
				rules: {
					sendCompany: {rules:[{
						required: true,
						errorMessage: "请输入工商营业执照上的企业名称",
						trigger: "blur"
					} ]},
					sendName: {rules:[{
						required: true,
						errorMessage: "请输入经办人真实姓名",
						trigger: "blur"
					} ]},
					sendMobile: {rules:[{
						required: true,
						errorMessage: "请输入经办人实名手机号",
						trigger: "blur"
					},
					 ]},
					},
					customerCompanyId:null,//当前选中的 常用企业id
					index:0,
					companyCopy:'',
			};
		},
		onLoad(option) {
		  this.companyCopy = option.companyCopy
		  this.index = option.index
		  uni.$on('copyCompanyData',data=>{
		  		this.ruleForm.sendCompany = data.sendCompany
				this.customerCompanyId = data.customerCompanyId
		  })
		  uni.$on('copyCompanyStaffData',data=>{
		  		this.ruleForm = data
		  })
		},
		methods: {
			/** 快捷选择联系人 */
			iconClick(){
			    let customerCompanyId = this.customerCompanyId?this.customerCompanyId:''
				uni.navigateTo({
					url:'/pages/sign/select/selectCompanyPersonal?companyCopy=' + true + '&customerCompanyId='+ customerCompanyId
				}) 
			},
			/** 快捷选择企业 */
			iconCompany(){
				uni.navigateTo({
					url:'/pages/sign/select/selectCompany?companyCopy=' + true
				})
			},
			/**确认*/
			confirm(){
				this.$refs.ruleForm.validate((valid) => {
					if (valid) {
							return false;
					}else{
						//返回指定页面 不刷新合同编号
						let pages = getCurrentPages();
						var num=pages.length
						//当前页面栈总数
						var backnum
						//需要返回的页数
						for(var i =0;i<num;i++){
							//循环找到指定页面路由所在的页数
							if(pages[i].route=='pages/sign/sign'){
								backnum=num-i-1
								//计算返回的层数，总数-指定页面页数-1
							}		
						}
						uni.navigateBack({
							delta:backnum //返回的页面数，如果 delta 大于现有页面数，则返回到首页。
						})
						uni.$emit('companyTableData',{ruleForm:this.ruleForm,index:this.index})
					}
				});
			},
		},
	};
</script>

<style lang="scss" scoped>
	page {
		background: $uni-bg-color;
	}
	::v-deep .uni-forms-item__label{padding: 0;}
	::v-deep .uni-forms-item .is-required{
		display: none;
	}
	.remark {
		font-size: 24rpx;
		color: #999999;
		word-wrap:break-word;
	}

	.per_title {
		font-size: 30rpx;
		color: #666666;
		border-bottom: 1rpx solid #d3d3d3;
		padding-bottom: 12rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		.iconfont {
			padding-right: 6rpx;
		}
	}
	.personal_form {
		margin-top: 40rpx;
		padding: 0 10rpx;
	}
	.ag_container {
		position: relative;
		padding:30rpx 40rpx 0;
	}
</style>
